home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 …SCII & the Runetime Code / ADC Developer CD (1992-07) (''Butch ASCII And The Runtime Code'')_iso / Dev.CD 199207.iso / Tools & Apps / Devices & Hardware / A⁄ROSE / MessageDispatcher / MultiThread.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-03  |  3.5 KB  |  155 lines  |  [TEXT/MPS ]

  1. /*
  2.     Header file for multi thread Macintosh task
  3.     
  4.     You can call CreateQueue to get a pointer to data structure for the queue
  5.     
  6.     You can call all A/ROSE routines through this structure
  7.     
  8.     You can call DestroyQueue to get rid of this structure
  9.     
  10.     Written by:    Anumele D. Raja
  11.     
  12.     Date:        March 19, 1991
  13.     
  14.     Copyright @ Apple Computer, Inc.  1991
  15.     
  16. */
  17.  
  18. #ifndef    __MULTITHREAD__
  19. #define    __MULTITHREAD__
  20.  
  21. #ifndef    __TYPES__
  22. #include    <Types.h>
  23. #endif
  24.  
  25. #ifndef    __RESOURCES__
  26. #include    <Resources.h>
  27. #endif
  28.  
  29. #ifndef __MEMORY__
  30. #include    <Memory.h>
  31. #endif
  32.  
  33. #ifndef    _os_defined_
  34. #include    "os.h"
  35. #endif
  36.  
  37. struct QueueEntry {
  38.         Handle            rsrcHandle;            // Reserved area
  39.         void            (*CloseQueue)(void);
  40.         void            (*FreeMsg)(mMessage *msgPtr);
  41.         char            (*GetCard)(void);
  42.         unsigned long    (*GetETick)(void);
  43.         tid_type        (*GetICCTID)(void);
  44.         struct IPCg        *(*GetIPCg)(void);
  45.         mMessage        *(*GetMsg)(void);
  46.         tid_type        (*GetNameTID)(void);
  47.         unsigned short    (*GetTickPS)(void);
  48.         tid_type        (*GetTID)(void);
  49.         short            (*IsLocal)(char *address);
  50.         void            (*KillReceive)(void);
  51.         short            (*LockRealArea)(void *virtualAddr, unsigned long length,
  52.                                 struct addressareas buffer[], unsigned long count);
  53.         tid_type        (*Lookup_Task)(char *object, char *type, tid_type nm_TID,
  54.                                             unsigned short *index);
  55.         short            (*NetCopy)(tid_type srcTID, void *srcAddress,
  56.                                     tid_type dstTID, void *dstAddress,
  57.                                             unsigned long byteCount);
  58.         tid_type        (*OpenQueue)(void (*UserProcedure)(void));
  59.         mMessage        *(*Receive)(unsigned long mID, tid_type mFrom,
  60.                                         unsigned short mCode, long timeOut,
  61.                                         void (*CompletionRoutine)(mMessage *));
  62.         char            (*Register_Task)(char object[], char type[], short local_only);
  63.         void            (*Send)(mMessage *msgPtr);
  64.         void            (*SwapTID)(mMessage *msgPtr);
  65.         void            (*UnLockRealArea)(void *virtualAddr, unsigned long length);
  66. #ifdef Dispatcher
  67.         void            (*OpenDispatch)(int queueSize);
  68.         void            (*CloseDispatch)(void);
  69.         Handle            despatchTblHdl;                    // Handle to the dispatch table
  70.         Handle             *msgQueueHdl;                    // Pointer to the queued up messages
  71.         int                msgQueueSize;
  72. #endif
  73. };
  74.  
  75. typedef struct QueueEntry QueueEntry;
  76.  
  77. //  Routine that reads in the MultiThread resource and returns a pointer
  78.  
  79. /*
  80.     Usage:
  81.     
  82.     In this program you are operating on another queue in addition to the
  83.         queue you get with plain OpenQueue
  84.     
  85.     QueueEntry *queuePtr;
  86.     
  87.     if (queuePtr = CreateQueue()) {
  88.         // Queue is ok
  89.         
  90.         mMessage *mspPtr;
  91.         tid_type    myTID;
  92.         
  93.         myTID = queuePtr->OpenQueue(0);
  94.         msgPtr = queuePtr->GetMsg();
  95.         .
  96.         .
  97.         .
  98.         queuePtr->Send(msgPtr);
  99.         .
  100.         .
  101.         .
  102.         msgPtr = queuePtr->Receive(OS_MATCH_ALL, myTID, OS_MATCH_ALL, -1, 0);
  103.         .
  104.         .
  105.         .
  106.         queuePtr->CloseQueue();
  107.         
  108.         DestroyQueue(queuePtr);
  109.         .
  110.         .
  111.         .
  112.     }
  113. */
  114.  
  115. const kRsrcType = 'mlti';
  116. const char kRsrcName[] = "\PMultiThread";
  117.  
  118. QueueEntry *CreateQueue()
  119. {
  120.     Handle         multiHdl;
  121.     QueueEntry     *qPtr;
  122.     ProcPtr        GetPtr;
  123.     
  124.     if ((multiHdl = GetNamedResource(kRsrcType, (ConstStr255Param)kRsrcName)) == 0)
  125.         return 0;
  126.     
  127.     DetachResource(multiHdl);        // Delink the handle from resource
  128.  
  129.     MoveHHi(multiHdl);        // Move it to high memory ready for locking
  130.     
  131.     HLock(multiHdl);
  132.     
  133.     GetPtr = *(ProcPtr*)multiHdl;
  134.     qPtr = (QueueEntry     *)StripAddress((void *)GetPtr());
  135.     qPtr->rsrcHandle = multiHdl;            // save the handle
  136. #ifdef Dispatcher
  137.     qPtr->despatchTblHdl = 0;                // indicate there is no despatch present
  138. #endif
  139.     return qPtr;
  140. }
  141.  
  142. void DestroyQueue(QueueEntry *qPtr)
  143. {
  144.     Handle multiHdl;
  145.     
  146.     if (qPtr) {
  147.         multiHdl = qPtr->rsrcHandle;
  148.         if (multiHdl) {
  149.             HUnlock(multiHdl);
  150.             DisposHandle(multiHdl);
  151.         }
  152.     }
  153. }
  154.  
  155. #endif